﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NiSis.Entities;
using NiSis.Data;

#endregion

namespace NiSis.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VReportProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VReportProviderBaseCore : EntityViewProviderBase<VReport>
	{
		#region Custom Methods
		
		
		#region UpdateUtenzeState
		
		/// <summary>
		///	This method wrap the 'UpdateUtenzeState' stored procedure. 
		/// </summary>
		/// <param name="idTraderPrecedente"> A <c>System.Int32?</c> instance.</param>
		/// <param name="newIdStato"> A <c>System.Int32?</c> instance.</param>
		/// <param name="nota"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void UpdateUtenzeState(System.Int32? idTraderPrecedente, System.Int32? newIdStato, System.String nota)
		{
			 UpdateUtenzeState(null, 0, int.MaxValue , idTraderPrecedente, newIdStato, nota);
		}
		
		/// <summary>
		///	This method wrap the 'UpdateUtenzeState' stored procedure. 
		/// </summary>
		/// <param name="idTraderPrecedente"> A <c>System.Int32?</c> instance.</param>
		/// <param name="newIdStato"> A <c>System.Int32?</c> instance.</param>
		/// <param name="nota"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void UpdateUtenzeState(int start, int pageLength, System.Int32? idTraderPrecedente, System.Int32? newIdStato, System.String nota)
		{
			 UpdateUtenzeState(null, start, pageLength , idTraderPrecedente, newIdStato, nota);
		}
				
		/// <summary>
		///	This method wrap the 'UpdateUtenzeState' stored procedure. 
		/// </summary>
		/// <param name="idTraderPrecedente"> A <c>System.Int32?</c> instance.</param>
		/// <param name="newIdStato"> A <c>System.Int32?</c> instance.</param>
		/// <param name="nota"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void UpdateUtenzeState(TransactionManager transactionManager, System.Int32? idTraderPrecedente, System.Int32? newIdStato, System.String nota)
		{
			 UpdateUtenzeState(transactionManager, 0, int.MaxValue , idTraderPrecedente, newIdStato, nota);
		}
		
		/// <summary>
		///	This method wrap the 'UpdateUtenzeState' stored procedure. 
		/// </summary>
		/// <param name="idTraderPrecedente"> A <c>System.Int32?</c> instance.</param>
		/// <param name="newIdStato"> A <c>System.Int32?</c> instance.</param>
		/// <param name="nota"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void UpdateUtenzeState(TransactionManager transactionManager, int start, int pageLength, System.Int32? idTraderPrecedente, System.Int32? newIdStato, System.String nota);
		
		#endregion

		
		#region UtenzeGasStoricoUpdateAll
		
		/// <summary>
		///	This method wrap the 'UtenzeGasStoricoUpdateAll' stored procedure. 
		/// </summary>
		/// <param name="idBatch"> A <c>System.Int32?</c> instance.</param>
		/// <param name="idState"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void UtenzeGasStoricoUpdateAll(System.Int32? idBatch, System.Int32? idState)
		{
			 UtenzeGasStoricoUpdateAll(null, 0, int.MaxValue , idBatch, idState);
		}
		
		/// <summary>
		///	This method wrap the 'UtenzeGasStoricoUpdateAll' stored procedure. 
		/// </summary>
		/// <param name="idBatch"> A <c>System.Int32?</c> instance.</param>
		/// <param name="idState"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void UtenzeGasStoricoUpdateAll(int start, int pageLength, System.Int32? idBatch, System.Int32? idState)
		{
			 UtenzeGasStoricoUpdateAll(null, start, pageLength , idBatch, idState);
		}
				
		/// <summary>
		///	This method wrap the 'UtenzeGasStoricoUpdateAll' stored procedure. 
		/// </summary>
		/// <param name="idBatch"> A <c>System.Int32?</c> instance.</param>
		/// <param name="idState"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void UtenzeGasStoricoUpdateAll(TransactionManager transactionManager, System.Int32? idBatch, System.Int32? idState)
		{
			 UtenzeGasStoricoUpdateAll(transactionManager, 0, int.MaxValue , idBatch, idState);
		}
		
		/// <summary>
		///	This method wrap the 'UtenzeGasStoricoUpdateAll' stored procedure. 
		/// </summary>
		/// <param name="idBatch"> A <c>System.Int32?</c> instance.</param>
		/// <param name="idState"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void UtenzeGasStoricoUpdateAll(TransactionManager transactionManager, int start, int pageLength, System.Int32? idBatch, System.Int32? idState);
		
		#endregion

		
		#region CleanUpHistory
		
		/// <summary>
		///	This method wrap the 'CleanUpHistory' stored procedure. 
		/// </summary>
		/// <param name="cdMese"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void CleanUpHistory(System.String cdMese)
		{
			 CleanUpHistory(null, 0, int.MaxValue , cdMese);
		}
		
		/// <summary>
		///	This method wrap the 'CleanUpHistory' stored procedure. 
		/// </summary>
		/// <param name="cdMese"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void CleanUpHistory(int start, int pageLength, System.String cdMese)
		{
			 CleanUpHistory(null, start, pageLength , cdMese);
		}
				
		/// <summary>
		///	This method wrap the 'CleanUpHistory' stored procedure. 
		/// </summary>
		/// <param name="cdMese"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void CleanUpHistory(TransactionManager transactionManager, System.String cdMese)
		{
			 CleanUpHistory(transactionManager, 0, int.MaxValue , cdMese);
		}
		
		/// <summary>
		///	This method wrap the 'CleanUpHistory' stored procedure. 
		/// </summary>
		/// <param name="cdMese"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void CleanUpHistory(TransactionManager transactionManager, int start, int pageLength, System.String cdMese);
		
		#endregion

		
		#region GetUtenze
		
		/// <summary>
		///	This method wrap the 'GetUtenze' stored procedure. 
		/// </summary>
		/// <param name="cdPool"> A <c>System.String</c> instance.</param>
		/// <param name="cdMese"> A <c>System.String</c> instance.</param>
		/// <param name="cdTraderPrec"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetUtenze(System.String cdPool, System.String cdMese, System.String cdTraderPrec)
		{
			return GetUtenze(null, 0, int.MaxValue , cdPool, cdMese, cdTraderPrec);
		}
		
		/// <summary>
		///	This method wrap the 'GetUtenze' stored procedure. 
		/// </summary>
		/// <param name="cdPool"> A <c>System.String</c> instance.</param>
		/// <param name="cdMese"> A <c>System.String</c> instance.</param>
		/// <param name="cdTraderPrec"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetUtenze(int start, int pageLength, System.String cdPool, System.String cdMese, System.String cdTraderPrec)
		{
			return GetUtenze(null, start, pageLength , cdPool, cdMese, cdTraderPrec);
		}
				
		/// <summary>
		///	This method wrap the 'GetUtenze' stored procedure. 
		/// </summary>
		/// <param name="cdPool"> A <c>System.String</c> instance.</param>
		/// <param name="cdMese"> A <c>System.String</c> instance.</param>
		/// <param name="cdTraderPrec"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetUtenze(TransactionManager transactionManager, System.String cdPool, System.String cdMese, System.String cdTraderPrec)
		{
			return GetUtenze(transactionManager, 0, int.MaxValue , cdPool, cdMese, cdTraderPrec);
		}
		
		/// <summary>
		///	This method wrap the 'GetUtenze' stored procedure. 
		/// </summary>
		/// <param name="cdPool"> A <c>System.String</c> instance.</param>
		/// <param name="cdMese"> A <c>System.String</c> instance.</param>
		/// <param name="cdTraderPrec"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet GetUtenze(TransactionManager transactionManager, int start, int pageLength, System.String cdPool, System.String cdMese, System.String cdTraderPrec);
		
		#endregion

		
		#region ConsolidateUsr
		
		/// <summary>
		///	This method wrap the 'ConsolidateUsr' stored procedure. 
		/// </summary>
		/// <param name="cdMeseAnno"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void ConsolidateUsr(System.String cdMeseAnno)
		{
			 ConsolidateUsr(null, 0, int.MaxValue , cdMeseAnno);
		}
		
		/// <summary>
		///	This method wrap the 'ConsolidateUsr' stored procedure. 
		/// </summary>
		/// <param name="cdMeseAnno"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void ConsolidateUsr(int start, int pageLength, System.String cdMeseAnno)
		{
			 ConsolidateUsr(null, start, pageLength , cdMeseAnno);
		}
				
		/// <summary>
		///	This method wrap the 'ConsolidateUsr' stored procedure. 
		/// </summary>
		/// <param name="cdMeseAnno"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void ConsolidateUsr(TransactionManager transactionManager, System.String cdMeseAnno)
		{
			 ConsolidateUsr(transactionManager, 0, int.MaxValue , cdMeseAnno);
		}
		
		/// <summary>
		///	This method wrap the 'ConsolidateUsr' stored procedure. 
		/// </summary>
		/// <param name="cdMeseAnno"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void ConsolidateUsr(TransactionManager transactionManager, int start, int pageLength, System.String cdMeseAnno);
		
		#endregion

		
		#region ChangeBatchState
		
		/// <summary>
		///	This method wrap the 'ChangeBatchState' stored procedure. 
		/// </summary>
		/// <param name="idBatch"> A <c>System.Int32?</c> instance.</param>
		/// <param name="newState"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void ChangeBatchState(System.Int32? idBatch, System.Int32? newState)
		{
			 ChangeBatchState(null, 0, int.MaxValue , idBatch, newState);
		}
		
		/// <summary>
		///	This method wrap the 'ChangeBatchState' stored procedure. 
		/// </summary>
		/// <param name="idBatch"> A <c>System.Int32?</c> instance.</param>
		/// <param name="newState"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void ChangeBatchState(int start, int pageLength, System.Int32? idBatch, System.Int32? newState)
		{
			 ChangeBatchState(null, start, pageLength , idBatch, newState);
		}
				
		/// <summary>
		///	This method wrap the 'ChangeBatchState' stored procedure. 
		/// </summary>
		/// <param name="idBatch"> A <c>System.Int32?</c> instance.</param>
		/// <param name="newState"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void ChangeBatchState(TransactionManager transactionManager, System.Int32? idBatch, System.Int32? newState)
		{
			 ChangeBatchState(transactionManager, 0, int.MaxValue , idBatch, newState);
		}
		
		/// <summary>
		///	This method wrap the 'ChangeBatchState' stored procedure. 
		/// </summary>
		/// <param name="idBatch"> A <c>System.Int32?</c> instance.</param>
		/// <param name="newState"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void ChangeBatchState(TransactionManager transactionManager, int start, int pageLength, System.Int32? idBatch, System.Int32? newState);
		
		#endregion

		
		#region GetUtenzeAll
		
		/// <summary>
		///	This method wrap the 'GetUtenzeAll' stored procedure. 
		/// </summary>
		/// <param name="cdPool"> A <c>System.String</c> instance.</param>
		/// <param name="cdMese"> A <c>System.String</c> instance.</param>
		/// <param name="cdTraderPrec"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetUtenzeAll(System.String cdPool, System.String cdMese, System.String cdTraderPrec)
		{
			return GetUtenzeAll(null, 0, int.MaxValue , cdPool, cdMese, cdTraderPrec);
		}
		
		/// <summary>
		///	This method wrap the 'GetUtenzeAll' stored procedure. 
		/// </summary>
		/// <param name="cdPool"> A <c>System.String</c> instance.</param>
		/// <param name="cdMese"> A <c>System.String</c> instance.</param>
		/// <param name="cdTraderPrec"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetUtenzeAll(int start, int pageLength, System.String cdPool, System.String cdMese, System.String cdTraderPrec)
		{
			return GetUtenzeAll(null, start, pageLength , cdPool, cdMese, cdTraderPrec);
		}
				
		/// <summary>
		///	This method wrap the 'GetUtenzeAll' stored procedure. 
		/// </summary>
		/// <param name="cdPool"> A <c>System.String</c> instance.</param>
		/// <param name="cdMese"> A <c>System.String</c> instance.</param>
		/// <param name="cdTraderPrec"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetUtenzeAll(TransactionManager transactionManager, System.String cdPool, System.String cdMese, System.String cdTraderPrec)
		{
			return GetUtenzeAll(transactionManager, 0, int.MaxValue , cdPool, cdMese, cdTraderPrec);
		}
		
		/// <summary>
		///	This method wrap the 'GetUtenzeAll' stored procedure. 
		/// </summary>
		/// <param name="cdPool"> A <c>System.String</c> instance.</param>
		/// <param name="cdMese"> A <c>System.String</c> instance.</param>
		/// <param name="cdTraderPrec"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet GetUtenzeAll(TransactionManager transactionManager, int start, int pageLength, System.String cdPool, System.String cdMese, System.String cdTraderPrec);
		
		#endregion

		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VReport&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VReport&gt;"/></returns>
		protected static VList&lt;VReport&gt; Fill(DataSet dataSet, VList<VReport> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VReport>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VReport&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VReport>"/></returns>
		protected static VList&lt;VReport&gt; Fill(DataTable dataTable, VList<VReport> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VReport c = new VReport();
					c.DsComune = (Convert.IsDBNull(row["DS_COMUNE"]))?string.Empty:(System.String)row["DS_COMUNE"];
					c.CdCliente = (Convert.IsDBNull(row["CD_CLIENTE"]))?string.Empty:(System.String)row["CD_CLIENTE"];
					c.DscStato = (Convert.IsDBNull(row["Dsc_Stato"]))?string.Empty:(System.String)row["Dsc_Stato"];
					c.AreaUscita = (Convert.IsDBNull(row["AreaUscita"]))?string.Empty:(System.String)row["AreaUscita"];
					c.CdStoricoMensileRete = (Convert.IsDBNull(row["CD_STORICO_MENSILE_RETE"]))?string.Empty:(System.String)row["CD_STORICO_MENSILE_RETE"];
					c.CdPrelievoAeeg = (Convert.IsDBNull(row["CD_PRELIEVO_AEEG"]))?string.Empty:(System.String)row["CD_PRELIEVO_AEEG"];
					c.SAreaUscita = (Convert.IsDBNull(row["S_Area_Uscita"]))?string.Empty:(System.String)row["S_Area_Uscita"];
					c.ConsumoAnnuoStimato = (Convert.IsDBNull(row["CONSUMO_ANNUO_STIMATO"]))?0:(System.Decimal?)row["CONSUMO_ANNUO_STIMATO"];
					c.CdPool = (Convert.IsDBNull(row["Cd_Pool"]))?string.Empty:(System.String)row["Cd_Pool"];
					c.DsSocieta = (Convert.IsDBNull(row["Ds_Societa"]))?string.Empty:(System.String)row["Ds_Societa"];
					c.CdPuntoFornitura = (Convert.IsDBNull(row["CD_PUNTO_FORNITURA"]))?string.Empty:(System.String)row["CD_PUNTO_FORNITURA"];
					c.DsCliente = (Convert.IsDBNull(row["DS_CLIENTE"]))?string.Empty:(System.String)row["DS_CLIENTE"];
					c.DsShipper = (Convert.IsDBNull(row["DsShipper"]))?string.Empty:(System.String)row["DsShipper"];
					c.Ltrader = (Convert.IsDBNull(row["LTrader"]))?string.Empty:(System.String)row["LTrader"];
					c.Capacita = (Convert.IsDBNull(row["Capacita"]))?0:(System.Decimal?)row["Capacita"];
					c.DtIns = (Convert.IsDBNull(row["dt_ins"]))?DateTime.MinValue:(System.DateTime?)row["dt_ins"];
					c.DtUpd = (Convert.IsDBNull(row["dt_upd"]))?DateTime.MinValue:(System.DateTime?)row["dt_upd"];
					c.DsTrasportatore = (Convert.IsDBNull(row["Ds_Trasportatore"]))?string.Empty:(System.String)row["Ds_Trasportatore"];
					c.IdStato = (Convert.IsDBNull(row["Id_Stato"]))?(int)0:(System.Int32?)row["Id_Stato"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VReport&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VReport&gt;"/></returns>
		protected VList<VReport> Fill(IDataReader reader, VList<VReport> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VReport entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VReport>("VReport",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VReport();
					}
					
					entity.SuppressEntityEvents = true;

					entity.DsComune = (reader.IsDBNull(((int)VReportColumn.DsComune)))?null:(System.String)reader[((int)VReportColumn.DsComune)];
					//entity.DsComune = (Convert.IsDBNull(reader["DS_COMUNE"]))?string.Empty:(System.String)reader["DS_COMUNE"];
					entity.CdCliente = (reader.IsDBNull(((int)VReportColumn.CdCliente)))?null:(System.String)reader[((int)VReportColumn.CdCliente)];
					//entity.CdCliente = (Convert.IsDBNull(reader["CD_CLIENTE"]))?string.Empty:(System.String)reader["CD_CLIENTE"];
					entity.DscStato = (reader.IsDBNull(((int)VReportColumn.DscStato)))?null:(System.String)reader[((int)VReportColumn.DscStato)];
					//entity.DscStato = (Convert.IsDBNull(reader["Dsc_Stato"]))?string.Empty:(System.String)reader["Dsc_Stato"];
					entity.AreaUscita = (System.String)reader[((int)VReportColumn.AreaUscita)];
					//entity.AreaUscita = (Convert.IsDBNull(reader["AreaUscita"]))?string.Empty:(System.String)reader["AreaUscita"];
					entity.CdStoricoMensileRete = (System.String)reader[((int)VReportColumn.CdStoricoMensileRete)];
					//entity.CdStoricoMensileRete = (Convert.IsDBNull(reader["CD_STORICO_MENSILE_RETE"]))?string.Empty:(System.String)reader["CD_STORICO_MENSILE_RETE"];
					entity.CdPrelievoAeeg = (reader.IsDBNull(((int)VReportColumn.CdPrelievoAeeg)))?null:(System.String)reader[((int)VReportColumn.CdPrelievoAeeg)];
					//entity.CdPrelievoAeeg = (Convert.IsDBNull(reader["CD_PRELIEVO_AEEG"]))?string.Empty:(System.String)reader["CD_PRELIEVO_AEEG"];
					entity.SAreaUscita = (reader.IsDBNull(((int)VReportColumn.SAreaUscita)))?null:(System.String)reader[((int)VReportColumn.SAreaUscita)];
					//entity.SAreaUscita = (Convert.IsDBNull(reader["S_Area_Uscita"]))?string.Empty:(System.String)reader["S_Area_Uscita"];
					entity.ConsumoAnnuoStimato = (reader.IsDBNull(((int)VReportColumn.ConsumoAnnuoStimato)))?null:(System.Decimal?)reader[((int)VReportColumn.ConsumoAnnuoStimato)];
					//entity.ConsumoAnnuoStimato = (Convert.IsDBNull(reader["CONSUMO_ANNUO_STIMATO"]))?0:(System.Decimal?)reader["CONSUMO_ANNUO_STIMATO"];
					entity.CdPool = (reader.IsDBNull(((int)VReportColumn.CdPool)))?null:(System.String)reader[((int)VReportColumn.CdPool)];
					//entity.CdPool = (Convert.IsDBNull(reader["Cd_Pool"]))?string.Empty:(System.String)reader["Cd_Pool"];
					entity.DsSocieta = (reader.IsDBNull(((int)VReportColumn.DsSocieta)))?null:(System.String)reader[((int)VReportColumn.DsSocieta)];
					//entity.DsSocieta = (Convert.IsDBNull(reader["Ds_Societa"]))?string.Empty:(System.String)reader["Ds_Societa"];
					entity.CdPuntoFornitura = (System.String)reader[((int)VReportColumn.CdPuntoFornitura)];
					//entity.CdPuntoFornitura = (Convert.IsDBNull(reader["CD_PUNTO_FORNITURA"]))?string.Empty:(System.String)reader["CD_PUNTO_FORNITURA"];
					entity.DsCliente = (reader.IsDBNull(((int)VReportColumn.DsCliente)))?null:(System.String)reader[((int)VReportColumn.DsCliente)];
					//entity.DsCliente = (Convert.IsDBNull(reader["DS_CLIENTE"]))?string.Empty:(System.String)reader["DS_CLIENTE"];
					entity.DsShipper = (reader.IsDBNull(((int)VReportColumn.DsShipper)))?null:(System.String)reader[((int)VReportColumn.DsShipper)];
					//entity.DsShipper = (Convert.IsDBNull(reader["DsShipper"]))?string.Empty:(System.String)reader["DsShipper"];
					entity.Ltrader = (reader.IsDBNull(((int)VReportColumn.Ltrader)))?null:(System.String)reader[((int)VReportColumn.Ltrader)];
					//entity.Ltrader = (Convert.IsDBNull(reader["LTrader"]))?string.Empty:(System.String)reader["LTrader"];
					entity.Capacita = (reader.IsDBNull(((int)VReportColumn.Capacita)))?null:(System.Decimal?)reader[((int)VReportColumn.Capacita)];
					//entity.Capacita = (Convert.IsDBNull(reader["Capacita"]))?0:(System.Decimal?)reader["Capacita"];
					entity.DtIns = (reader.IsDBNull(((int)VReportColumn.DtIns)))?null:(System.DateTime?)reader[((int)VReportColumn.DtIns)];
					//entity.DtIns = (Convert.IsDBNull(reader["dt_ins"]))?DateTime.MinValue:(System.DateTime?)reader["dt_ins"];
					entity.DtUpd = (reader.IsDBNull(((int)VReportColumn.DtUpd)))?null:(System.DateTime?)reader[((int)VReportColumn.DtUpd)];
					//entity.DtUpd = (Convert.IsDBNull(reader["dt_upd"]))?DateTime.MinValue:(System.DateTime?)reader["dt_upd"];
					entity.DsTrasportatore = (reader.IsDBNull(((int)VReportColumn.DsTrasportatore)))?null:(System.String)reader[((int)VReportColumn.DsTrasportatore)];
					//entity.DsTrasportatore = (Convert.IsDBNull(reader["Ds_Trasportatore"]))?string.Empty:(System.String)reader["Ds_Trasportatore"];
					entity.IdStato = (reader.IsDBNull(((int)VReportColumn.IdStato)))?null:(System.Int32?)reader[((int)VReportColumn.IdStato)];
					//entity.IdStato = (Convert.IsDBNull(reader["Id_Stato"]))?(int)0:(System.Int32?)reader["Id_Stato"];
					entity.AcceptChanges();
					entity.SuppressEntityEvents = false;
					
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VReport"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VReport"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VReport entity)
		{
			reader.Read();
			entity.DsComune = (reader.IsDBNull(((int)VReportColumn.DsComune)))?null:(System.String)reader[((int)VReportColumn.DsComune)];
			//entity.DsComune = (Convert.IsDBNull(reader["DS_COMUNE"]))?string.Empty:(System.String)reader["DS_COMUNE"];
			entity.CdCliente = (reader.IsDBNull(((int)VReportColumn.CdCliente)))?null:(System.String)reader[((int)VReportColumn.CdCliente)];
			//entity.CdCliente = (Convert.IsDBNull(reader["CD_CLIENTE"]))?string.Empty:(System.String)reader["CD_CLIENTE"];
			entity.DscStato = (reader.IsDBNull(((int)VReportColumn.DscStato)))?null:(System.String)reader[((int)VReportColumn.DscStato)];
			//entity.DscStato = (Convert.IsDBNull(reader["Dsc_Stato"]))?string.Empty:(System.String)reader["Dsc_Stato"];
			entity.AreaUscita = (System.String)reader[((int)VReportColumn.AreaUscita)];
			//entity.AreaUscita = (Convert.IsDBNull(reader["AreaUscita"]))?string.Empty:(System.String)reader["AreaUscita"];
			entity.CdStoricoMensileRete = (System.String)reader[((int)VReportColumn.CdStoricoMensileRete)];
			//entity.CdStoricoMensileRete = (Convert.IsDBNull(reader["CD_STORICO_MENSILE_RETE"]))?string.Empty:(System.String)reader["CD_STORICO_MENSILE_RETE"];
			entity.CdPrelievoAeeg = (reader.IsDBNull(((int)VReportColumn.CdPrelievoAeeg)))?null:(System.String)reader[((int)VReportColumn.CdPrelievoAeeg)];
			//entity.CdPrelievoAeeg = (Convert.IsDBNull(reader["CD_PRELIEVO_AEEG"]))?string.Empty:(System.String)reader["CD_PRELIEVO_AEEG"];
			entity.SAreaUscita = (reader.IsDBNull(((int)VReportColumn.SAreaUscita)))?null:(System.String)reader[((int)VReportColumn.SAreaUscita)];
			//entity.SAreaUscita = (Convert.IsDBNull(reader["S_Area_Uscita"]))?string.Empty:(System.String)reader["S_Area_Uscita"];
			entity.ConsumoAnnuoStimato = (reader.IsDBNull(((int)VReportColumn.ConsumoAnnuoStimato)))?null:(System.Decimal?)reader[((int)VReportColumn.ConsumoAnnuoStimato)];
			//entity.ConsumoAnnuoStimato = (Convert.IsDBNull(reader["CONSUMO_ANNUO_STIMATO"]))?0:(System.Decimal?)reader["CONSUMO_ANNUO_STIMATO"];
			entity.CdPool = (reader.IsDBNull(((int)VReportColumn.CdPool)))?null:(System.String)reader[((int)VReportColumn.CdPool)];
			//entity.CdPool = (Convert.IsDBNull(reader["Cd_Pool"]))?string.Empty:(System.String)reader["Cd_Pool"];
			entity.DsSocieta = (reader.IsDBNull(((int)VReportColumn.DsSocieta)))?null:(System.String)reader[((int)VReportColumn.DsSocieta)];
			//entity.DsSocieta = (Convert.IsDBNull(reader["Ds_Societa"]))?string.Empty:(System.String)reader["Ds_Societa"];
			entity.CdPuntoFornitura = (System.String)reader[((int)VReportColumn.CdPuntoFornitura)];
			//entity.CdPuntoFornitura = (Convert.IsDBNull(reader["CD_PUNTO_FORNITURA"]))?string.Empty:(System.String)reader["CD_PUNTO_FORNITURA"];
			entity.DsCliente = (reader.IsDBNull(((int)VReportColumn.DsCliente)))?null:(System.String)reader[((int)VReportColumn.DsCliente)];
			//entity.DsCliente = (Convert.IsDBNull(reader["DS_CLIENTE"]))?string.Empty:(System.String)reader["DS_CLIENTE"];
			entity.DsShipper = (reader.IsDBNull(((int)VReportColumn.DsShipper)))?null:(System.String)reader[((int)VReportColumn.DsShipper)];
			//entity.DsShipper = (Convert.IsDBNull(reader["DsShipper"]))?string.Empty:(System.String)reader["DsShipper"];
			entity.Ltrader = (reader.IsDBNull(((int)VReportColumn.Ltrader)))?null:(System.String)reader[((int)VReportColumn.Ltrader)];
			//entity.Ltrader = (Convert.IsDBNull(reader["LTrader"]))?string.Empty:(System.String)reader["LTrader"];
			entity.Capacita = (reader.IsDBNull(((int)VReportColumn.Capacita)))?null:(System.Decimal?)reader[((int)VReportColumn.Capacita)];
			//entity.Capacita = (Convert.IsDBNull(reader["Capacita"]))?0:(System.Decimal?)reader["Capacita"];
			entity.DtIns = (reader.IsDBNull(((int)VReportColumn.DtIns)))?null:(System.DateTime?)reader[((int)VReportColumn.DtIns)];
			//entity.DtIns = (Convert.IsDBNull(reader["dt_ins"]))?DateTime.MinValue:(System.DateTime?)reader["dt_ins"];
			entity.DtUpd = (reader.IsDBNull(((int)VReportColumn.DtUpd)))?null:(System.DateTime?)reader[((int)VReportColumn.DtUpd)];
			//entity.DtUpd = (Convert.IsDBNull(reader["dt_upd"]))?DateTime.MinValue:(System.DateTime?)reader["dt_upd"];
			entity.DsTrasportatore = (reader.IsDBNull(((int)VReportColumn.DsTrasportatore)))?null:(System.String)reader[((int)VReportColumn.DsTrasportatore)];
			//entity.DsTrasportatore = (Convert.IsDBNull(reader["Ds_Trasportatore"]))?string.Empty:(System.String)reader["Ds_Trasportatore"];
			entity.IdStato = (reader.IsDBNull(((int)VReportColumn.IdStato)))?null:(System.Int32?)reader[((int)VReportColumn.IdStato)];
			//entity.IdStato = (Convert.IsDBNull(reader["Id_Stato"]))?(int)0:(System.Int32?)reader["Id_Stato"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VReport"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VReport"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VReport entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.DsComune = (Convert.IsDBNull(dataRow["DS_COMUNE"]))?string.Empty:(System.String)dataRow["DS_COMUNE"];
			entity.CdCliente = (Convert.IsDBNull(dataRow["CD_CLIENTE"]))?string.Empty:(System.String)dataRow["CD_CLIENTE"];
			entity.DscStato = (Convert.IsDBNull(dataRow["Dsc_Stato"]))?string.Empty:(System.String)dataRow["Dsc_Stato"];
			entity.AreaUscita = (Convert.IsDBNull(dataRow["AreaUscita"]))?string.Empty:(System.String)dataRow["AreaUscita"];
			entity.CdStoricoMensileRete = (Convert.IsDBNull(dataRow["CD_STORICO_MENSILE_RETE"]))?string.Empty:(System.String)dataRow["CD_STORICO_MENSILE_RETE"];
			entity.CdPrelievoAeeg = (Convert.IsDBNull(dataRow["CD_PRELIEVO_AEEG"]))?string.Empty:(System.String)dataRow["CD_PRELIEVO_AEEG"];
			entity.SAreaUscita = (Convert.IsDBNull(dataRow["S_Area_Uscita"]))?string.Empty:(System.String)dataRow["S_Area_Uscita"];
			entity.ConsumoAnnuoStimato = (Convert.IsDBNull(dataRow["CONSUMO_ANNUO_STIMATO"]))?0:(System.Decimal?)dataRow["CONSUMO_ANNUO_STIMATO"];
			entity.CdPool = (Convert.IsDBNull(dataRow["Cd_Pool"]))?string.Empty:(System.String)dataRow["Cd_Pool"];
			entity.DsSocieta = (Convert.IsDBNull(dataRow["Ds_Societa"]))?string.Empty:(System.String)dataRow["Ds_Societa"];
			entity.CdPuntoFornitura = (Convert.IsDBNull(dataRow["CD_PUNTO_FORNITURA"]))?string.Empty:(System.String)dataRow["CD_PUNTO_FORNITURA"];
			entity.DsCliente = (Convert.IsDBNull(dataRow["DS_CLIENTE"]))?string.Empty:(System.String)dataRow["DS_CLIENTE"];
			entity.DsShipper = (Convert.IsDBNull(dataRow["DsShipper"]))?string.Empty:(System.String)dataRow["DsShipper"];
			entity.Ltrader = (Convert.IsDBNull(dataRow["LTrader"]))?string.Empty:(System.String)dataRow["LTrader"];
			entity.Capacita = (Convert.IsDBNull(dataRow["Capacita"]))?0:(System.Decimal?)dataRow["Capacita"];
			entity.DtIns = (Convert.IsDBNull(dataRow["dt_ins"]))?DateTime.MinValue:(System.DateTime?)dataRow["dt_ins"];
			entity.DtUpd = (Convert.IsDBNull(dataRow["dt_upd"]))?DateTime.MinValue:(System.DateTime?)dataRow["dt_upd"];
			entity.DsTrasportatore = (Convert.IsDBNull(dataRow["Ds_Trasportatore"]))?string.Empty:(System.String)dataRow["Ds_Trasportatore"];
			entity.IdStato = (Convert.IsDBNull(dataRow["Id_Stato"]))?(int)0:(System.Int32?)dataRow["Id_Stato"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VReportFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VReport"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VReportFilterBuilder : SqlFilterBuilder<VReportColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VReportFilterBuilder class.
		/// </summary>
		public VReportFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VReportFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VReportFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VReportFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VReportFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VReportFilterBuilder

	#region VReportParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VReport"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VReportParameterBuilder : ParameterizedSqlFilterBuilder<VReportColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VReportParameterBuilder class.
		/// </summary>
		public VReportParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VReportParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VReportParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VReportParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VReportParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VReportParameterBuilder
	
	#region VReportSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VReport"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class VReportSortBuilder : SqlSortBuilder<VReportColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VReportSqlSortBuilder class.
		/// </summary>
		public VReportSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion VReportSortBuilder

} // end namespace
